var loadingcount = 0;
var _$ = layui.jquery;
var loading = layui.loading;
function showloading(t) {
	if (t) {//如果是true则显示loading
		loading = layer.load(1, {
			shade: [0.5, '#fff'] //0.1透明度的白色背景
		});
		loadingcount++;
	} else {//如果是false则关闭loading
		loadingcount--;
		if(loadingcount == 0){
			layer.closeAll('loading');
		}
	}
}

function setBtnPermission(){
    _$('[btnPermission]').each(function(){
		var actionid = $(this).attr('btnPermission');
		if (!hasPower(actionid)) {
			$(this).remove();
		}
	});
}

function hasPower(value){
	var isExist=false;
	var actionsStr = sessionStorage.getItem("actions");
	if(actionsStr == undefined || actionsStr == null){
		return false;
	}else{
		var actionArr = value.split(',');
		if(actionArr.length > 1){
			for(var i=0;i<actionArr.length;i++){
				if(actionsStr.indexOf(actionArr[i])> -1 ){
					isExist=true;
					break;
				}
			}
		}else{
			if(actionsStr.indexOf(value)> -1 ){
				isExist=true;
			}
		}
	}

	return isExist;
}

function stringToDate(str){
	var dateStrs = str.split("-");
	var year = parseInt(dateStrs[0], 10);
	var month = parseInt(dateStrs[1], 10) - 1;
	var day = parseInt(dateStrs[2], 10);

	var date = new Date(year, month, day);

	return date;

}
//兼容assign
// IE 兼容方法
if (typeof Object.assign != 'function') {
    Object.assign = function (target) {
        'use strict';
        if (target == null) {
            throw new TypeError('Cannot convert undefined or null to object');
        }

        target = Object(target);
        for (var index = 1; index < arguments.length; index++) {
            var source = arguments[index];
            if (source != null) {
                for (var key in source) {
                    if (Object.prototype.hasOwnProperty.call(source, key)) {
                        target[key] = source[key];
                    }
                }
            }
        }
        return target;
    };
}

function previewResource(url) {
    var ind= url.lastIndexOf(".");
    var ext = url.substr(ind+1).toLowerCase();
    if (ext=='pdf'){
        previewPdf(url);
    }else{
		window.open(url);
		// window.location.href = url;
    }
}
//预览pdf
function previewPdf(url){
    let pdfjs = APP_URL + "/statics/component/pdfjs/generic/web/viewer.html?file="+ url;
    window.open(pdfjs);
}
